﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SoulHackerCUnite.Data
{
    public class ResultToShow
    {
        public Demon Demon1 { get; set; }
        public Demon Demon2 { get; set; }
        public Demon Demon3 { get; set; }
        public Demon Result { get; set; }
        public string Plus { get; set; }
        public string Plus2 { get; set; }
        public string Equal { get; set; }

        public ResultToShow()
        {
            this.Plus = "+";
            this.Equal = "=";
        }

        public override bool Equals(object obj)
        {
            if(obj is ResultToShow)
            {
                ResultToShow target = (obj as ResultToShow);

                if (target.Result == null||this.Result==null)
                    return false;

                if (this.Result.Name != target.Result.Name)
                    return false;

                //if one is 3 other is 2, then they are not equal.
                if((this.Demon3!=null&&target.Demon3==null)||(this.Demon3==null&&target.Demon3!=null))
                {
                    return false;
                }

                if(this.Demon3!=null)
                {
                    if (this.Demon1.Name == target.Demon1.Name)
                        return ((this.Demon2.Name == target.Demon2.Name) && (this.Demon3.Name == target.Demon3.Name)) ||
                               ((this.Demon2.Name == target.Demon3.Name) && (this.Demon3.Name == target.Demon2.Name));
                    else if (this.Demon2.Name == target.Demon2.Name)
                        return ((this.Demon1.Name == target.Demon3.Name) && (this.Demon3.Name == target.Demon1.Name));
                    else if (this.Demon3.Name == target.Demon3.Name)
                        return ((this.Demon1.Name == target.Demon2.Name) && (this.Demon2.Name == target.Demon1.Name));
                    else
                        return ((this.Demon1.Name == target.Demon2.Name) && (this.Demon2.Name == target.Demon3.Name) &&
                                (this.Demon3.Name == target.Demon1.Name));
                }
                else
                {
                    return ((this.Demon2.Name == target.Demon2.Name) && (this.Demon1.Name == target.Demon1.Name)) ||
                               ((this.Demon2.Name == target.Demon1.Name) && (this.Demon1.Name == target.Demon2.Name));
                }
            }
            return false;
        }
    }
}
